package com.hnl.action.user;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.aware.HNLAuthAware;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.UserDAO;
import com.hnl.to.User;
import com.hnl.to.wrapper.UserWrapper;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
public class SearchConsultantList  extends HttpServlet implements HNLAuthAware {
	public static final Logger LOG = LoggerFactory
	.getLogger(SearchConsultantList.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		try{
			String userEmail = req.getParameter("userEmail");
			UserDAO userDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getUserDAO();
			Collection<User> userCollection = userDAO.loadUserByUserEmail(userEmail);
			Collection<UserWrapper> userWrapperCollection = new Vector<UserWrapper>();
			
			for (User user : userCollection) {
				UserWrapper newUserWrapper = new UserWrapper(user);
				newUserWrapper.getUserIDText();
				newUserWrapper.getModifiedUserIDText();
				userWrapperCollection.add(newUserWrapper);
			}

			PrintWriter writer = resp.getWriter();
			writer.println(JSONResponseUtil
					.getJSONObjectString(userWrapperCollection));			
		}catch (DAOException e) {
			LOG.error("error laoding Talent", e);
		}
		
	}
	
	

}
